package com.xufei.common.domain.common;

import java.util.HashMap;
import java.util.Map;

public class AjaxJson extends HashMap<String, Object> {
    //
    private static final long serialVersionUID = 1L;

    public AjaxJson() {
        put("code", 0000);
        put("msg", "success");
    }

    public static AjaxJson error() {
        return error(500, "未知异常，请联系管理员");
    }

    public static AjaxJson error(String msg) {
        return error(500, msg);
    }

    public static AjaxJson error(int code, String msg) {
        AjaxJson r = new AjaxJson();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public static AjaxJson ok(String msg) {
        AjaxJson r = new AjaxJson();
        r.put("msg", msg);
        return r;
    }

    public static AjaxJson data(Object obj) {
        AjaxJson r = new AjaxJson();
        r.put("data", obj);
        return r;
    }

    public static AjaxJson ok(Map<String, Object> map) {
        AjaxJson r = new AjaxJson();
        r.putAll(map);
        return r;
    }

    public static AjaxJson ok() {
        return new AjaxJson();
    }

    @Override
    public AjaxJson put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
